<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    body {
      margin: 0;
    }

    #box {
      width: 300px;
      height: 300px;
      border: 1px solid red;
      /*margin: 100px 10px 10px 100px;*/
      position: absolute;
      top: 200px;
      left: 200px;
    }
  </style>
</head>
<body>
  <div id="box" style="left: 200px;top: 200px;">
    
  </div>
  <script src="common.js"></script>
  <script>
    var box = document.getElementById('box');
    box.onclick = function (e) {
      // 获取盒子在页面上的位置
      //console.log(this.offsetLeft);
      //console.log(this.offsetTop);
      e = e || window.event;
      // 获取鼠标在盒子中的位置 = 鼠标的坐标 - 盒子的坐标
      // var x = e.pageX
      var x = getPage(e).pageX - this.offsetLeft;
      var y = getPage(e).pageY - this.offsetTop;
      console.log(x);
      console.log(y);
    }
  </script>
</body>
</html>
